﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-header">
            <h1 class="page-title">添加战队</h1>
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a class="icon wb-home" href="javascript:;">战队管理</a>
                </li>
                <li class="breadcrumb-item active">添加战队</li>
            </ol>
        </div>
        <div class="page-content">
            <div class="panel">
                <div class="panel-body">
                    <div class="example-wrap">
                        <div class="example">
                            <div class="form-group">
                                <label class="control-label" for="inputInlineUsername">战队名称</label>
                                <input type="text" class="form-control" id="zhanduimingcheng" name="zhanqumingcheng" placeholder="战区名称" autocomplete="off" />
                            </div>
                            <div id="div1" class="form-group">
                                <label class="control-label" for="inputInlinePassword">所属战区</label>
                                <select class="form-control" id="suoshuzhanqu">
                                </select>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-1">
                                    <input type="button" id="TianJia" onclick="Add()" class="btn btn-block btn-info" value="添加" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#SpanGongSi").click();
        zhanqu();
    });

    function zhanqu() {
        $.ajax({
            type: 'post',
            url: '../ZhanDui/GetZhanQu',
            async: false,
            dataType: 'json',
            success: function (date) {
                var ddl = $("#suoshuzhanqu");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].zhanQuMingCheng).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    }

    function Add() {
        var zhanduimingcheng = $("#zhanduimingcheng").val();
        var suoshuzhanqu = jQuery("#suoshuzhanqu").val();
        if (zhanduimingcheng == "") {
            alert("战队名称不能为空");
        } else if (suoshuzhanqu == "0") {
            alert("所属战队不能为空");
        }  else {
            $.ajax({
                type: 'post',
                url: '../ZhanDui/ZhanDuiTianJia',
                dataType: 'text',
                async: true,
                data: { zhanduimingcheng: zhanduimingcheng, suoshuzhanqu: suoshuzhanqu},
                success: function (result) {
                    if (result == "1") {
                        alert("添加成功");
                        location.href = "../ZhanDui/ZhanDuiList";
                    } else {
                        alert("添加失败");
                    }
                }
            });
        }
    }
</script>